<?php
namespace common\modules\taxonomy;

class ModuleInfo extends \common\core\modularity\ModuleInfo
{
    public function init()
    {
        parent::init();

        $this->id = 'taxonomy';
        $this->name = '分类';
        $this->description = '分类管理模块，用于内容组织';
        $this->version = '1.0.0';
        $this->icon = '<i class="fa fa-thumb-tack"></i>';
        $this->has_backend = true;
        $this->has_frontend = false;
        $this->has_api = false;

        $this->is_system = false;
    }

    public function install()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        $this->createTable('{{%taxonomy}}', [
            'id' => $this->primaryKey(11),
            'parent_id' => 'int(11) NOT NULL',
            'category_id' => 'varchar(64) NOT NULL',
            'name' => 'varchar(64) NOT NULL',
            'url_alias' => 'varchar(64) DEFAULT NULL',
            'redirect_url' => 'varchar(128) DEFAULT NULL',
            'thumbnail' => 'varchar(128) DEFAULT NULL',
            'description' => 'varchar(256) DEFAULT NULL',
            'page_size' => 'int(11) DEFAULT NULL',
            'list_view' => 'varchar(64) DEFAULT NULL',
            'list_layout' => 'varchar(64) DEFAULT NULL',
            'detail_view' => 'varchar(64) DEFAULT NULL',
            'detail_layout' => 'varchar(64) DEFAULT NULL',
            'seo_title' => 'varchar(256) DEFAULT NULL',
            'seo_keywords' => 'varchar(256) DEFAULT NULL',
            'seo_description' => 'varchar(256) DEFAULT NULL',
            'content_count' => $this->integer(11)->defaultValue(0),
            'sort' => 'int(11) NULL'
        ], $tableOptions);

        $this->createTable('{{%taxonomy_category}}', [
            'id' => 'varchar(64) NOT NULL',
            'name' => 'varchar(64) NOT NULL',
            'description' => 'varchar(512) DEFAULT NULL'
        ], $tableOptions);

        $this->addPrimaryKey('pk_taxonomy_category', '{{%taxonomy_category}}', 'id');

        $this->createTable('{{%taxonomy_content}}', [
            'id' => $this->primaryKey(11),
            'taxonomy_id' => 'int(11) NOT NULL',
            'content_id' => 'int(11) NOT NULL'
        ], $tableOptions);
    }

    public function uninstall()
    {
        $this->dropTable('{{%taxonomy_content}}');

        $this->dropTable('{{%taxonomy_category}}');

        $this->dropTable('{{%taxonomy}}');
    }
}